/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.buzzwords.behaviors;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author potlow
 */
public class UserEmailBehavior extends UserBehavior {

    @Override
    public List<Object> read(Object value) {
        String email;
        if (value instanceof String) {
            email = (String) value;
        } else {
            throw new IllegalArgumentException("Search value must be a String");
        }

        EntityManager em = emf.createEntityManager();
        Query query = em.createNamedQuery("User.findByEmail").setParameter("email", email);
        List<Object> users = query.getResultList();
        em.close();

        return users;
    }
}
